package com.njym.java.security.app.rest;

import com.njym.java.security.app.biz.FamilyRelationshipBiz;
import com.njym.java.security.app.entity.FamilyRelationship;
import com.njym.java.security.app.entity.FamilyRelationshipVo;
import com.njym.java.security.app.entity.FamilyType;
import com.njym.java.security.common.msg.ObjectRestResponse;
import com.njym.java.security.common.rest.BaseController;
import com.njym.java.security.common.util.ResponseUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("familyRelationship")
public class FamilyRelationshipController extends BaseController<FamilyRelationshipBiz,FamilyRelationship> {

    /**
     * 获取家庭成员
     * @param familyTypeId
     * @return
     */
    @RequestMapping(value = "/getFamilyUser", method = RequestMethod.GET)
    @ResponseBody
    public Object getFamilyUser(String familyTypeId) {
        if (!familyTypeId.equals("undefined")) {
            List<FamilyRelationshipVo> list = baseBiz.query(Integer.parseInt(familyTypeId));
            Map<String, Object> data = new HashMap<>(1);
            data.put("list",list);
            return new ObjectRestResponse<FamilyRelationshipVo>().rel(true).data(data);
        } else {
            return ResponseUtil.fail(40301, "错误！");
        }
    }

    /**
     * 删除家庭成员
     * @param
     * @return
     */
    @RequestMapping(value = "/deleteFamilyUser", method = RequestMethod.GET)
    @ResponseBody
    public Object deleteFamilyUser(String id) {
        if (!id.equals("undefined")) {
            FamilyRelationship familyRelationship =  baseBiz.selectById(Integer.parseInt(id));
            familyRelationship.setDeleted(1);
            baseBiz.updateById(familyRelationship);
            return   ResponseUtil.ok(familyRelationship);
        } else {
            return ResponseUtil.fail(40301, "错误！");
        }
    }




    /**
     * 获取家庭
     * @param
     * @return
     */
    @RequestMapping(value = "/getFamilyName", method = RequestMethod.GET)
    @ResponseBody
    public Object getFamilyName(String id) {
        if (!id.equals("undefined")) {
            List<FamilyType> list  =  baseBiz.getFamilyName(Integer.parseInt(id));
            return   ResponseUtil.ok(list);
        } else {
            return ResponseUtil.fail(40301, "错误！");
        }

    }

}